#include<stdio.h>
#include<malloc.h>
#define Maxsize 50
typedef char ElemType;
char Z;
typedef struct
{
    ElemType data[Maxsize];
    int top;
}SqStack;

void InitStack(SqStack*& s)
{
    s = (SqStack*)malloc(sizeof(SqStack));
    s->top = -1;
}
void DestroyStack(SqStack*& s)
{
    free(s);
}
bool StackEmpty(SqStack *s)
{
    return(s->top == -1);
} 
bool Push(SqStack*& s, ElemType e)
{
    if (s->top == Maxsize - 1)
        return false;
    s->top++;
    s->data[s->top] = e;
    return true;
}
bool Pop(SqStack*& s, ElemType& e)
{
    if (s->top == -1)
        return false;
    e = s->data[s->top];
    s->top--; 
    return true;
}
bool GetTop(SqStack* s, ElemType& e)
{
    if (s->top == -1)
        return false;
    e = s->data[s->top];
    return true;
} 
int main()
{
    SqStack* s;
    printf("顺序栈的基本运算\n");
    printf("初始化栈\n");
    InitStack(s);
    printf("判断栈s是否非空: %s\n", (StackEmpty(s) ? "空" : "非空"));
    printf("依次进栈元素a,b,c,c,d,e\n");
    Push(s, 'a');
    Push(s, 'b');
    Push(s, 'c');
    Push(s, 'd');
    Push(s, 'e');
    printf("判断栈s是否非空: %s\n", (StackEmpty(s) ? "空" : "非空"));
    printf("依次出栈");
    while (s->top!=-1)
    {
        Pop(s, Z);
        printf("%c", Z);
    }
    printf("\n");
    printf("判断栈s是否非空: %s\n", (StackEmpty(s) ? "空" : "非空"));
    printf("释放栈\n");
    DestroyStack(s);

}